﻿Public Class position3D
    Private _x As Single
    Private _y As Single
    Private _z As Single

    Public Property X() As Single
        Get
            Return _x
        End Get
        Set(ByVal value As Single)
            _x = value
        End Set
    End Property

    Public Property Y() As Single
        Get
            Return _y
        End Get
        Set(ByVal value As Single)
            _y = value
        End Set
    End Property

    Public Property Z() As Single
        Get
            Return _z
        End Get
        Set(ByVal value As Single)
            _z = value
        End Set
    End Property

    Public Function ToXElement() As XElement
        Dim result As XElement = <pos3d x=<%= _x.ToString %> y=<%= _y.ToString %> z=<%= _z %>/>

        Return result
    End Function

    Public Sub LoadXML(ByVal locationXML As String)
        Dim locX As XElement = GetXElement(locationXML)

        If IsNothing(locX) Then
            Exit Sub
        End If

        Dim xS As String = locX.<pos3d>.@x
        Dim yS As String = locX.<pos3d>.@y
        Dim zS As String = locX.<pos3d>.@z

        If Single.TryParse(xS, _x) = False Then
            _x = Nothing
        End If

        If Single.TryParse(yS, _y) = False Then
            _y = Nothing
        End If

        If Single.TryParse(zS, _z) = False Then
            _z = Nothing
        End If
    End Sub
End Class
